#include <exception>
#include <string>
#include <iostream>
// 自定义异常类，用于文件读取错误
class FileReadException : public std::exception {
private:
    std::string message;  // 错误消息
    int errorCode;        // 错误代码

public:
    // 构造函数
    FileReadException(const std::string& msg, int code = 0)
        : message(msg), errorCode(code) {}

    // 返回完整的错误描述
    const char* what() const noexcept override {
        static std::string fullMessage;
        fullMessage = "FileReadException: " + message + " (Error code: " + std::to_string(errorCode) + ")";
        return fullMessage.c_str();
    }

    // 获取错误代码
    int getErrorCode() const {
        return errorCode;
    }
};



void readFile(const std::string& filename) {
    // 假设的错误检测逻辑
    bool fileNotFound = true;  // 假设文件未找到
    if (fileNotFound) {
        throw FileReadException("File not found", 404);
    }
}

int main() {
    try {
        readFile("example.txt");
    } catch (const FileReadException& e) {
        std::cerr << "An error occurred: " << e.what() << std::endl;
    }
    return 0;
}